#ifndef SWANLINK_FINANCE_FRAMEWORKS_CLIENT_ICCREADER_OBSERVER_H
#define SWANLINK_FINANCE_FRAMEWORKS_CLIENT_ICCREADER_OBSERVER_H
#include <js_native_api.h>
#include <js_native_api_types.h>
#include <napi/native_common.h>
#include <napi/native_api.h>
#include <mutex>
#include <nocopyable.h>
#include <string>
#include <vector>
#include <stack>
#include <memory>
#include "iccreader_observer_stub.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"

namespace SwanLink {
namespace Finance {
using namespace OHOS;

class NapiSearchResult {
 public:
  NapiSearchResult();
  ~NapiSearchResult();
  napi_env  env;
  napi_ref  func_succ_ref;
  napi_ref  func_fail_ref;

  void OnResult(int status, const ResultData &data);
  void OnError(int status, const std::string &err);
};

class SearchResultObserver: public IccReaderObserverStub {
 public:
  SearchResultObserver();
  virtual ~SearchResultObserver();

  void PushObserver(const napi_env &env, const napi_value &listener);
  void PopObserver();

  void OnResult(int status, const ResultData &data) override;
  void OnError(int status, const std::string &err) override;

  DISALLOW_COPY(SearchResultObserver);
 private:
  NapiSearchResult*  searcher_;
  std::shared_ptr<OHOS::AppExecFwk::EventHandler> handler_;
  std::mutex  mutex_;
};
}  // namespace Finance
}  // namespace SwanLink
#endif  // SWANLINK_FINANCE_FRAMEWORKS_CLIENT_ICCREADER_OBSERVER_H
